let vm = new Vue({
  el: '#tongtai',
  data: {
    value: "",
    lookPopup: false,    
    assignor: false,     //分配人
    activeName: ['1'],
    activeNames2: ['1'],
    
    
    form: {
      page: 1,
      limit: 10
    },
    loading: false, //控制加载状态
    finished: false, //控制加载状态
    dataList: [],                                                           //总列表
    lookList: {all:[], process:[], fabric:[], accessories:[]},              // 查看

    assignorList: [],
    assignorName: "",
    assignorRemark: "",
  },
  methods: {
    onLoad() {
      this.form.page++;
      this.getData();
    },

    getData(searchCallback) {
      leiku.post(
        "http://dongtai.fsslpc.com/api/2020041712942245",
        {page: this.form.page,
          limit: this.form.limit,Number: this.value,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''},
        (res) => {
          let data = res.data;
          if(searchCallback){
            searchCallback(data);
          }
          
          if (!data.t.length) {
            this.finished = true;
            return;
          } else {
            this.dataList.push.apply(this.dataList, data.t);
            this.loading = false;
          }
        }
      );
    },
    // 搜索
    onSearch() {
      this.dataList = [];
      this.form.page = 1;
      if (this.value) {
        // 传一个回调函数进去，作判断
        this.getData((res)=>{
          if(!res.t.length){
            this.$toast.fail({message:'查无此订单',duration: 2500})
          }
        });
      } else if (!this.value.length) {
        this.getData();
      }
    },
    onclear () {
      this.getData();
    },

    // 查看按钮
    lookPopupBtn(val) {
      this.lookList.all = val;
      leiku.post('http://dongtai.fsslpc.com/api/2020041713170991', {page: 1, limit: this.form.limit, Id: this.lookList.all.TempleDevelopColorId, tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
        let data = res.data.t;
        if (data.length) {
          data.forEach( v => {
            this.lookList.process.push(v)
          })
        }
        this.lookList.process.some(v=> {
          if (v.state == 1) {
            this.assignorName = v.executor
          }
        })        
        this.lookList.process.some(v=> {
          if (v.state == 2) {
            this.assignorRemark = v.executor
          }
        })        
      })
      leiku.post('http://dongtai.fsslpc.com/api/2020041713280210', {page: 1,limit: this.form.limit,Id: this.lookList.all.TempleDevelopColorId, tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
        let data = res.data.t;
        if (data.length) {
          data.forEach( v => {
            this.lookList.fabric.push(v)
          })
        }
      })
      leiku.post('http://dongtai.fsslpc.com/api/2020041713257403', {page: 1,limit: this.form.limit,Id: this.lookList.all.TempleDevelopColorId, tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
        let data = res.data.t;
        if (data.length) {
          data.forEach( v => {
            this.lookList.accessories.push(v)
          })
        }
      })
      this.lookPopup = true;
    },
    closeLookPopup() {
      this.lookList.all=[];
      this.lookList.process=[];
      this.lookList.fabric=[];
      this.lookList.accessories=[];
      this.lookList.assignorName='';
      this.lookList.assignorRemark='';
      this.lookPopup = false;
    },

    // 分配人弹出层
    peoplePopupBtn(val) {
      this.lookList.all = val;
      leiku.post('http://dongtai.fsslpc.com/api/2020041713096920', {page: 1,limit: this.form.limit,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
        let data = res.data.t;
        if (data.length) {
          this.assignorList = data;
        }
        console.log(this.assignorList)
      })
      this.assignor = true;
    },
    onClose() {
      this.lookList.all = [];
      this.assignorList = [];
      this.assignor = false
    },
    // 分配人选择
    onSelect_assignorlist(val) {
      this.$dialog.confirm({title: val.Name, message: "确认分配？"})
        .then(() => {
          leiku.post('http://dongtai.fsslpc.com/api/2020041713010044', {uid: val.Id, id: this.lookList.all.TempleDevelopColorId, dh: this.lookList.all.Number,DesignerId: this.lookList.all.DesignerId,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
            this.$toast({message:'分配成功！'})

            leiku.post(
              "http://dongtai.fsslpc.com/api/2020041712942245",
              {page: 1,
                limit: this.dataList.length,Number: this.value,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''},
              (res) => {
                let data = res.data;
                this.dataList = data.t;
              }
            );
            this.assignor = false;
            this.lookPopup = false;
            // window.location.reload();
          })
        })
        .catch(()=>{})
    },

    // 分配人弹出层————内部
    peoplePopupBtn2() {
      leiku.post('http://dongtai.fsslpc.com/api/2020041713096920', {page: 1,limit: this.form.limit,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
        let data = res.data.t;
        if (data.length) {
          this.assignorList = data;
        }
        // console.log(this.assignorList)
      })
      this.assignor = true;      
    },

    // 完成按钮
    sureBtn() {
      this.$dialog.confirm({message: "确认完成？"})
        .then(() => {
          leiku.post('http://dongtai.fsslpc.com/api/2020041713176454', {id: this.lookList.all.TempleDevelopColorId, dh: this.lookList.all.Number,remark: this.lookList.all.Remark,patternfile:this.lookList.all.patternfile,maijiaImage: this.lookList.all.maijiaImage,maijiaFile: this.lookList.all.maijiaFile,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
            this.$toast({message:'确认成功！'})
            leiku.post(
              "http://dongtai.fsslpc.com/api/2020041712942245",
              {page: 1,
                limit: this.dataList.length,Number: this.value,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''},
              (res) => {
                let data = res.data;
                this.dataList = data.t;
              }
            );
            this.lookPopup = false;
          })
        })
        .catch(()=>{})
    }
  },
  mounted() {
    this.getData();
  },    
})